const download = require('download-git-repo')
const ora = require('ora')
const chalk = require('chalk')

function downloadFun(downURL, project) {
	const spinner = ora().start()
	spinner.text = '代码正在下载, 请稍候...'
	download(
		downURL,
		project,
		{
			clone: true
		},
		(err) => {
			if (!err) {
				spinner.succeed('下载成功')
				console.log(chalk.blue.bold('Done! '), chalk.bold('Done! '))
				console.log(chalk.yellowBright('cd ' + project))
				console.log(chalk.yellowBright('npm install '))
				console.log(chalk.yellowBright('npm run dev '))
				return
			}

			spinner.fail('下载失败: ')
			console.log(err)
		}
	)
}
module.exports = downloadFun
